import axios from 'axios'

const BaseURL = 'http://localhost:3000/';

const Service = axios.create({
  timeout: 5000,
  baseURL: BaseURL,
  method: 'post',
  headers: {
    'Content-Type': 'application/json;charset=UTF-8'
  }
});
// 添加请求拦截器
Service.interceptors.request.use(
    config => {
      return config;
    }
);

// 添加响应拦截器
Service.interceptors.response.use(
    response => {
      return response.data;
    }, error => {
      console.log('TCL: error', error);
      return Promise.reject(error)
    }
);

export const get = function (url, params) {
  return Service.get(url, {
    params: params
  });
};

export const post = function (url, data) {
  return Service.post(url, JSON.stringify(data));
};
